package cn.by.wms.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.by.wms.entity.*;
import cn.by.wms.dao.WarehouseDao;
import cn.by.wms.service.WarehouseService;

import java.util.List;

/**
 * 库房;(206_warehouse)表服务实现类
 * @author : heimi
 * @date : 2024-11-22
 */
@Service
public class WarehouseService {

    @Autowired
    private WarehouseDao warehouseDao;

    public List<Warehouse> select(WarehouseQuery query) {
        LambdaQueryWrapper<Warehouse> wapper =new  LambdaQueryWrapper();
        wapper.eq(query.getId() != null, Warehouse::getId, query.getId() );
        wapper.like(query.getName() != null, Warehouse::getName, query.getName() );
        wapper.eq(query.getStatus() != null, Warehouse::getStatus, query.getStatus());
        return warehouseDao.selectList(wapper);
    }

    public Integer insert(Warehouse warehouse) {
        return warehouseDao.insert(warehouse);
    }

    public Integer update(Warehouse warehouse) {
        LambdaUpdateWrapper<Warehouse> updateWrapper =new  LambdaUpdateWrapper();
        updateWrapper.eq(Warehouse::getId, warehouse.getId());
        updateWrapper.set(warehouse.getName() != null, Warehouse::getName, warehouse.getName() );
        updateWrapper.set(warehouse.getStatus()!=null,Warehouse::getStatus , warehouse.getStatus());
        updateWrapper.set(warehouse.getBrief()!=null, Warehouse::getBrief,warehouse.getBrief());
        updateWrapper.set(warehouse.getImg()!=null, Warehouse::getImg,warehouse.getImg());
        updateWrapper.set(warehouse.getSeq()!=null, Warehouse::getSeq,warehouse.getSeq());
        return warehouseDao.update(updateWrapper);
    }

    public Integer delete(Integer id) {
        return warehouseDao.deleteById(id);
    }


}